<?php
namespace Home\Controller;

use Think\Controller;

/**
*@desc 普通用户后台
*/
class HelpController extends CommonController {

    public function __construct(){
        parent::__construct();

        // 用户信息
        if($this->role != -1){// 游客
            $this->user_email = session('user_email');
            $this->uid = session('uid');
            $this->assign('user_email',$this->user_email);
        }

        $this->assign('role',$this->role);
    }

    //所有错误跳转
    public function __call($method,$args){
        if(IS_POST){
            $this->ajaxReturn( array('status'=>404,'msg'=>'400 bad request','data'=>null));
        }elseif( file_exists_case($this->view->parseTemplate()) ){
            $this->display();
        }else{
            $this->error('链接无效');
        }
    }

    public function index(){
    	$this->assign('head_title','帮助中心－云途数据市场');
    	$this->display("index");
    }
    
    public function user_agreen(){
    	$this->assign('head_title','帮助中心－云途数据市场');
    	$this->display("user_agreement");
    }

    //数据征集令页面
    public function dataorder(){
		$this->assign('head_title','数据征集令－云途数据市场');
        $this->display();
    }

    //数据征集令邮件发送
    public function sendEmail(){
        $content = I('post.data');
        $contact = I('post.name');
        $tel = I('post.phone');
        $email = I('post.email');
        if(empty($content) || empty($contact) || empty($tel) || empty($email)) return $this->ajaxReturn( array('status'=>4001,'msg'=>'缺少必要参数','data'=>null) );

        $data = array('content'=>$content,'contact'=>$contact,'tel'=>$tel,'email'=>$email);
        $mail_content = activityCollectionEmailString($name='数据征集令',$data);
        if(!$mail_content) return $this->ajaxReturn( array('status'=>4002,'msg'=>'缺少必要参数','data'=>null) );

        $to = "service@37degree.com";
        // $to = "704819236@qq.com";
        $title = "数据征集令-【云途数据】";
        sendMail($to, $title, $mail_content);

        return $this->ajaxReturn( array('status'=>200,'msg'=>'OK','data'=>null) );
    }
}
